<!-- 设置 -->
<template>
	<view class="list">
		<view v-for="(item,index) in vdata.list" class="item" @click="item.func">{{ item.name }}</view>
	</view>
	<!-- 授权登录弹窗 -->
	<gzLoginPopup ref="gzLoginPopupRef" v-model:isLogin="vdata.isLogin"></gzLoginPopup>
</template>

<script setup>
	import { onShow } from '@dcloudio/uni-app'
	import { ref, reactive, getCurrentInstance } from 'vue'
	import storageManage from '@/util/storageManage.js'
	
	const { $infoBox } = getCurrentInstance().appContext.config.globalProperties
	
	const gzLoginPopupRef = ref()
	
	onShow(()=>{
		vdata.isLogin = storageManage.isLogin()
	})
	
	const vdata = reactive({
		isLogin: false,	// 默认用户未登录
		list: [
			{ name: '个人资料', func: toFansInfo, checkLogin: true },
			{ name: '清除本地缓存', func: clearStorage, checkLogin: false },
			{ name: '用户投诉', func: toUserComplain, checkLogin: false,},
			{ name: '服务中心', func: toServiceCenter, checkLogin: false,},
			{ name: '注销账号', func: clearAccountNumber, checkLogin: false },

		]
	})
	
	/**
	 * 跳转个人资料
	 */
	function toFansInfo() {
		getApp().preventActive(()=>{
			if(!vdata.isLogin){
				gzLoginPopupRef.value.open()
				return
			}
			uni.navigateTo({
				url: `/pageUser/fansInfo/index?isUser=${true}`
			})
		})
	}
	
	// 跳转用户投诉
	function toUserComplain (){
		uni.navigateTo({
			url:'/pageUser/setting/userComplain'
		})
	}
	// 跳转服务中心
	function toServiceCenter(){
		uni.navigateTo({
			url:'/pageUser/setting/serviceCenter/index'
		})
	}
	
		function clearAccountNumber(){
			getApp().preventActive(()=>{
				if(!vdata.isLogin){
					gzLoginPopupRef.value.open()
					return
				}
				uni.navigateTo({
					url: `/pageUser/logoff/index?isUser=${true}`
				})
			})
		}
	
		
	/**
	 * 清除缓存
	 */
	function clearStorage(){
		uni.showModal({
			title: '提示',
			content: '请确认是否清除本地缓存？',
			success({ cancel }) {
				if(cancel) return
				storageManage.token('',true)
				storageManage.dataKey('',true)
				storageManage.version('',true)
				uni.clearStorageSync()
				uni.createCacheManager().clearCaches()
				$infoBox.successToast('缓存清除成功',{ duration: 2000 })
				setTimeout(()=>{
					uni.reLaunch({
						url: '/pages/welcome/index'
					})
				},2000)
			}
		})
	}
</script>

<style lang="less">
	.list{
		min-height: 100vh;
		overflow: hidden;
		background-color: #f9f9f9;
		.item{
			padding: 24rpx 48rpx;
			background-color: #fff;
			margin-bottom: 24rpx;
		}
	}
</style>